package com.ruoyi.iot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.iot.domain.IotDeviceData;
import com.ruoyi.iot.service.IIotDeviceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备数据Controller
 *
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/iot/device/data")
public class IotDeviceDataController extends BaseController {
    @Autowired
    private IIotDeviceDataService iotDeviceDataService;

    /**
     * 查询设备数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotDeviceData iotDeviceData) {
        startPage();
        List<IotDeviceData> list = iotDeviceDataService.selectIotDeviceDataList(iotDeviceData);
        return getDataTable(list);
    }

    /**
     * 导出设备数据列表
     */
    @Log(title = "设备数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotDeviceData iotDeviceData) {
        List<IotDeviceData> list = iotDeviceDataService.selectIotDeviceDataList(iotDeviceData);
        ExcelUtil<IotDeviceData> util = new ExcelUtil<IotDeviceData>(IotDeviceData.class);
        util.exportExcel(response, list, "设备数据数据");
    }

    /**
     * 获取设备数据详细信息
     */
    @GetMapping(value = "/{dataId}")
    public AjaxResult getInfo(@PathVariable("dataId") Long dataId) {
        return success(iotDeviceDataService.selectIotDeviceDataByDataId(dataId));
    }

    /**
     * 新增设备数据
     */
    @Log(title = "设备数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody IotDeviceData iotDeviceData) {
        return toAjax(iotDeviceDataService.insertIotDeviceData(iotDeviceData));
    }

    /**
     * 修改设备数据
     */
    @Log(title = "设备数据", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody IotDeviceData iotDeviceData) {
        return toAjax(iotDeviceDataService.updateIotDeviceData(iotDeviceData));
    }

    /**
     * 删除设备数据
     */
    @Log(title = "设备数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}")
    public AjaxResult remove(@PathVariable Long[] dataIds) {
        return toAjax(iotDeviceDataService.deleteIotDeviceDataByDataIds(dataIds));
    }
}
